package logger;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class FenetreLogger extends JFrame {
	
	public static final FenetreLogger INSTANCE = new FenetreLogger();
	
	JPanel listeErreurs;
	
	private FenetreLogger()
	{
		super("Console d'erreurs");
		setLayout(new BorderLayout());
		
		listeErreurs = new JPanel();
		listeErreurs.setLayout(new GridLayout(0,1));

		add(new JScrollPane(listeErreurs), BorderLayout.CENTER);
		setSize(600,400);
	}
	
	public void addInfo(String msg)
	{
		JPanel ligne = new JPanel();
		ligne.setLayout(new GridLayout(1,0));
		
		JLabel type = new JLabel("INFO", JLabel.CENTER);
		type.setForeground(Color.green);
		ligne.add(type);
		
		ligne.add(new JLabel(msg, JLabel.CENTER));
		
		listeErreurs.add(ligne);
		validate();
	}
	public void addWarn(String msg)
	{
		JPanel ligne = new JPanel();
		ligne.setLayout(new GridLayout(1,0));
		
		JLabel type = new JLabel("WARN", JLabel.CENTER);
		type.setForeground(Color.orange);
		ligne.add(type);
		
		ligne.add(new JLabel(msg, JLabel.CENTER));
		
		listeErreurs.add(ligne);
		validate();
	}
	public void addError(String msg)
	{
		JPanel ligne = new JPanel();
		ligne.setLayout(new GridLayout(1,0));
		
		JLabel type = new JLabel("ERROR", JLabel.CENTER);
		type.setForeground(Color.red);
		ligne.add(type);
		
		ligne.add(new JLabel(msg, JLabel.CENTER));
		
		listeErreurs.add(ligne);
		validate();
	}
}
